﻿#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

// 比较
int cmp_int(const void* p1, const void* p2)
{
	return *(int*)p1 - *(int*)p2;
}
//交换
void tmp(char* p1, char* p2, int wd)
{
	for (int i = 0; i < wd; i++)
	{
		char num = p1[i];
		p1[i] = p2[i];
		p2[i] = num;
	}
}
//使用冒泡排序模拟qsort
void my_qsort(const void* base, int sz, int wd, int (*cmp)(const void*, const void*))
{
	for (int i = 0; i < sz - 1; i++)
	{
		for (int j = 0; j < sz - 1 - i; j++)
		{
			if (cmp((char*)base + j * wd, (char*)base + (j + 1) * wd) > 0)
			{
				tmp((char*)base + j * wd, (char*)base + (j + 1) * wd, wd);
			}
		}
	}
}
int main()
{
	int arr[] = { 3,5,7,2,8,4,6,9,1,0 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	my_qsort(arr, sz, sizeof(arr[0]), cmp_int);
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}
	return 0;
}